<?php

namespace App\Admin\Controllers\Bargain;

use App\Admin\Repositories\Bargain\CmcPromotionBargainGood;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CmcPromotionBargainGoodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CmcPromotionBargainGood(), function (Grid $grid) {
            $grid->withBorder();
            $grid->export()->filename('砍价商品');
            $grid->quickSearch(['bargain_name', 'id']);
            $grid->column('id')->sortable();
            $grid->column('bargain_type')->image($server=null,110,100);
            $grid->column('bargain_name')->editable(true);
            $grid->column('first_bargain_price')->editable(true);
            $grid->column('floor_price')->editable(true);
            $grid->column('is_fenxiao');
            $grid->column('bargain_num');
            $grid->column('is_own');
            $grid->column('bargain_stock');
            $grid->column('buy_type');
            $grid->column('bargain_time');
            $grid->column('end_time');
            $grid->column('status', '状态')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '关闭',
                    1 => '开启',
                ])
            );
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcPromotionBargainGood(), function (Show $show) {
            $show->field('id');
            $show->field('bargain_id');
            $show->field('goods_id');
            $show->field('sku_id');
            $show->field('first_bargain_price');
            $show->field('bargain_stock');
            $show->field('floor_price');
            $show->field('bargain_name');
            $show->field('is_fenxiao');
            $show->field('buy_type');
            $show->field('bargain_type');
            $show->field('bargain_num');
            $show->field('bargain_time');
            $show->field('remark');
            $show->field('start_time');
            $show->field('end_time');
            $show->field('status');
            $show->field('status_name');
            $show->field('is_own');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcPromotionBargainGood(), function (Form $form) {
            $form->block(12, function (Form\BlockForm $form) {
                $form->title('选择砍价商品');
                $form->image('bargain_type');
            });
            $form->block(12, function (Form\BlockForm $form) {
                    // 显示底部提交按钮
                $form->title('填写基础信息');
                $form->row(function (Form\Row $row) {
                    $row->text('bargain_name');
                });
                $form->row(function (Form\Row $row) {
                    $row->width(4)->text('remark_name');
                    $row->width(4)->number('sore');
                });


                $form->row(function (Form\Row $row) {
                    $row->width(4)->datetime('start_time');                    $row->width(4)->datetime('end_time');
                });
                $form->row(function (Form\Row $row) {
                    $row->number('bargain_num');
                });
                $form->row(function (Form\Row $row) {
                    $row->number('is_own');
                });
                $form->row(function (Form\Row $row) {
                    $row->number('shopp_num');
                });
                $form->row(function (Form\Row $row) {
                    $row->select('is_shipping')->options(
                        [
                            0 => '不包邮',
                            1 => '包邮',
                        ]
                    );
                });
                $form->row(function (Form\Row $row) {
                    $row->radio('status')->options(['0' => '关闭', 1  => '开启'])->default(0);
                    $row->number('first_bargain_price');
                    $row->number('floor_price');
                });

                $form->next(function (Form\BlockForm $form) {
                    // 显示底部提交按钮
                    $form->title('修改商品详情');
                    $form->showFooter();
                    $form->editor('remark_text','砍价活动详情');
                    $form->editor('remark','活动规则说明');

                });

            });

        });

    }
}
